source ~/.bash_profile

# 部署配置
# 钉钉告警配置
ACCESS_TOKEN=e9526eb327a1c1d731518db1593c623bcd240ee3fd4f0dee0feb63d0dabd6fe6
# docker 服务器
DEPLOY_HOSTS=("118.89.121.139")
# 区分环境变量配置
if [ ${PROFILE} == 'dev' ]; then
    SERVER_PORT="1${SERVER_PORT}"
fi

# 代码所在目录
cd ${SERVER_FOLDER}/${SERVER_NAME}
# 编译打包
mvn clean package -DskipTests=true -U -P ${PROFILE}
# 检查mvn打包是否成功
if [ ! -f "target/${SERVER_NAME}.jar" ]; then
  echo "mvn编译打包失败. target/${SERVER_NAME}.jar 不存在."
  curl -fsSL https://gitee.com/hdzhangQAQ/twisly-riptide-doc/raw/master/shell/deploy/tool_send_ding.sh | \
    SERVER_LABEL=后端项目 \
    SERVER_NAME=${SERVER_NAME} \
    PROCESS=编译失败 \
    DEPLOY_HOST=${DEPLOY_HOST} \
    PROFILE=${PROFILE} \
    BUILD_USER=${BUILD_USER} \
    ACCESS_TOKEN=${ACCESS_TOKEN} \
  sh -
  exit -1
fi

for DEPLOY_HOST in ${DEPLOY_HOSTS[@]}; do
# 钉钉提醒-部署开始
curl -fsSL https://gitee.com/hdzhangQAQ/twisly-riptide-doc/raw/master/shell/deploy/tool_send_ding.sh | \
  SERVER_LABEL=后端项目 \
  SERVER_NAME=${SERVER_NAME} \
  PROCESS=部署开始 \
  DEPLOY_HOST=${DEPLOY_HOST} \
  PROFILE=${PROFILE} \
  BUILD_USER=${BUILD_USER} \
  ACCESS_TOKEN=${ACCESS_TOKEN} \
sh -

DOCKER_HOST="https://${DEPLOY_HOST}:2375"
# 推送镜像
mvn docker:stop docker:remove docker:build docker:push docker:start \
-Ddocker.skip.push=${SKIP_DOCKER_PUSH} \
-Ddocker.host=${DOCKER_HOST} \
-Dserver.port=${SERVER_PORT} \
-P ${PROFILE}

# 钉钉提醒-部署成功
curl -fsSL https://gitee.com/hdzhangQAQ/twisly-riptide-doc/raw/master/shell/deploy/tool_send_ding.sh | \
  SERVER_LABEL=后端项目 \
  SERVER_NAME=${SERVER_NAME} \
  PROCESS=部署成功 \
  DEPLOY_HOST=${DEPLOY_HOST} \
  PROFILE=${PROFILE} \
  BUILD_USER=${BUILD_USER} \
  ACCESS_TOKEN=${ACCESS_TOKEN} \
sh -
done
